package cn.ljy.uem.dao;

import cn.ljy.authority.dao.BaseMapper;
import cn.ljy.uem.model.SchoolStudent;
import cn.ljy.uem.model.SchoolTeachingTaskStudent;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

/**
 * @description 教学班学生的数据层操作类
 * @author 廖振豪
 * @date 2022-7-18 15:22
 */

@Mapper
public interface SchoolTeachingTaskStudentMapper {

    /**
     * 根据指定教学班包含的学生集合
     * @param teachingTaskId
     * @return
     */
    List<Long> findAllStudentByTeachingTaskId(Integer teachingTaskId);

    /**
     * 根据指定教学班获取拥有的所有学生数量
     * @param teachingTaskId
     * @return
     */
    @Select("select count(1) from school_teachingtask_student where teachingtask_id = #{teachingTaskId}")
    int countAllStudentByTeachingTaskId(Integer teachingTaskId);

    /**
     * 根据指定教学班获取拥有的所有学生类型数量
     * @param teachingTaskId type
     * @return
     */
    @Select("select count(1) from school_teachingtask_student where teachingtask_id = #{teachingTaskId} and `type`=#{type}")
    int countByUserIdAndRoleId(Serializable teachingTaskId, Serializable type);

    /**
     * 查找单个学生 findById
     * @param teachingTaskId
     * @param studentId
     * @return
     */
    SchoolTeachingTaskStudent findByTeachingTaskIdAndStudentId(Serializable teachingTaskId, Serializable studentId);

    /**
     * 插入教学班和学生及学生类型的关系
     * @return
     */
    @Insert("insert into school_teachingtask_student(teachingtask_id,student_id,type,create_time) values(#{teachingTaskId},#{studentId},#{type},now())")
    int save(Serializable teachingTaskId, Serializable studentId,Serializable type);

    /**
     * 修改学生类型
     * @return
     */
    @Update("update school_teachingtask_student set type=#{type},update_time=now() where teachingtask_id=#{teachingTaskId} and student_id=#{studentId}")
    void update(SchoolTeachingTaskStudent student);
    /**
     * 移除教学班和学生的关系
     * @param teachingTaskId
     * @param studentId
     * @return
     */
    @Delete("delete from school_teachingtask_student where teachingtask_id=#{teachingTaskId} and student_id=#{studentId}")
    void delete(Integer teachingTaskId, Serializable studentId);


    /**
     * 获取表中符合条件的所有记录
     * 说明：如果查询条件为null，则表示查询所有记录
     * @return
     */
    List<SchoolTeachingTaskStudent> findAll(@Param(value = "objectQuery")Object objectQuery);


    /**
     * 获取符合查询条件的记录数，一般与query配合使用
     * @param objectQuery 查询条件类
     * @return 符合查询条件的记录数
     */
    int count(@Param(value = "objectQuery")Object objectQuery);

    /**
     * 读取部分记录，一般配合业务层分页方法展示
     * @param offset 第一条记录索引（从0开始）
     * @param length 显示记录个数（指从第一条记录开始，显示第N条）
     * @param objectQuery 查询条件类
     * @return 符合查询条件的记录
     */
    List<SchoolTeachingTaskStudent> find(@Param(value = "offset") final int offset, @Param(value = "length") final int length,@Param(value = "objectQuery")Object objectQuery);

    /**
     * 删除该教学班对应的教学班与学生的关系  按照教学班Id删除整个教学班学生
     * @param teachingTaskIds 教学班集合
     */
    int deleteByTeachingTaskIds(java.io.Serializable[] teachingTaskIds);

    //通过学生id查找记录
    @Select("SELECT * FROM school_teachingtask_student WHERE school_teachingtask_student.student_id=#{studentId}")
    List<SchoolTeachingTaskStudent> findStudentbyid(Serializable studentId);
}
